﻿using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;

using UI.WebControls.ControlsBase;
using Model.AuthModel;
using BLL.AuthModel;
namespace UI.WebControls
{
    public class AuthFunc : CheckBoxListBase
    {
        /// <summary>
        /// 设置默认的模块拥有的权限
        /// </summary>
        public IList<AuthInfo> DefaultAuth = new List<AuthInfo>();

        /// <summary>
        /// 重载基类加载事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                IList<FuncInfo> list = new FuncBLL().ListFunc();
                if (list != null && list.Count > 0)
                {
                    foreach (FuncInfo info in list)
                        base.Items.Add(new ListItem(info.FuncName, info.FuncID.ToString()));
                }
                if (DefaultAuth != null) 
                {
                    foreach (AuthInfo info in DefaultAuth)
                        base.DefaultSelect.Add(info.Func.FuncID.ToString());
                }
            }
            base.OnLoad(e);
        }        
    }
}
